import * as env from './env'
import * as store from './store'
import * as lang from './lang'
import * as math from './math'
import * as ajax from './ajax'

export default {
  install (Vue) {
    Vue.prototype.$env = env
    Vue.prototype.$cache = store
    Vue.prototype.$lang = lang
    Vue.prototype.$math = math
    Vue.prototype.$ajax = ajax
    Vue.filter('mathNumber', (value, def) => {
      return math.number(value, def)
    })
    Vue.filter('mathMoney', (value, prefix, def) => {
      return math.money(value, prefix, def)
    })

    Vue.filter('mathMoneyNum', (value, prefix, def) => {
      return math.moneyNum(value, prefix, def)
    })
    Vue.filter('mathMoneyIf', (value, flag = true, prefix, def) => {
      if (flag === true) {
        return math.money(value, prefix, def)
      } else {
        return value
      }
    })
    Vue.filter('mathAdd', (value, ...args) => {
      return math.add(value, ...args)
    })
    Vue.filter('mathRound', (value, numDigits, upOrDown) => {
      return math.round(value, numDigits, upOrDown)
    })
    Vue.filter('mathSub', (value, ...args) => {
      return math.sub(value, ...args)
    })
    Vue.filter('mathDiv', (value, ...args) => {
      return math.div(value, ...args)
    })
    Vue.filter('mathMul', (value, ...args) => {
      return math.mul(value, ...args)
    })
    Vue.filter('mathMax', (value, ...args) => {
      return math.max(value, ...args)
    })
    Vue.filter('mathMin', (value, ...args) => {
      return math.min(value, ...args)
    })
  }
}
